/**
 * Project hdmap
 * @author shengjialiang
 * @version v1.0
 */


#ifndef _LOGGER_H
#define _LOGGER_H

#include "map_helper/HelperConfig.h"
#include "map_common/ObjectQueue.h"
#include <osg/Array>
#include "OpenThreads/Thread"
#include "OpenThreads/Condition"
#include "OpenThreads/Mutex"

namespace Helper
{
    enum LoggerLevel
    {
        LL_NORMAL,
        LL_ERROR,
        LL_WARNING,
        LL_LOW
    };

    class MAP_HELPE_EXPORT CLogger 
        : public OpenThreads::Thread
    {
        struct LogInfo
        {
            std::string info;
            LoggerLevel level;
        };

    public:
        CLogger();

        ~CLogger();

        static CLogger* instance();

        static void releaseInstance();

        void run();

        bool write(const std::string& in_logInfo, const LoggerLevel& in_logLevel = LL_NORMAL);

        void reset();
        
    protected:
        void perform();
    private:
        Common::CThreadSafeQueue<LogInfo> mLogInfoQueue;
        OpenThreads::Condition mRequestCondition;
        OpenThreads::Mutex mRequestMutex;
        bool mRunning;
        bool mIsWorking;
    };
}

#define LOGGER(x) Helper::CLogger::instance()->write(x);
#endif //_LOGGER_H